<#compress>
<!DOCTYPE html>
<html>
<head>
<#include "plat/include.ftl"/>
<#assign _CODE = "${RequestParameters['CODE']}" />
<#if _CODE!=''>
    <#assign commands = operators />
    <#assign _availableRoles = availableRoles />
    <#assign _roles = roles />

</#if>
    <script type='text/javascript' src='${base}/js/plugins/laydate/laydate.js'></script>
    <script type="text/javascript" src="${base}/js/plugins/buttons/spin.min.js"></script>
    <script type="text/javascript" src="${base}/js/plugins/buttons/ladda.min.js"></script>
</head>
<body>
<div class="ibox-content animated fadeInRight">
    <form id="optForm" class="form-horizontal">
        <input name="opercode" id="opercode" type="hidden"
               value="${operator.opercode}"/>
        <table class="table table-bordered" style="max-width: 600px;margin: 0 auto">
            <tr>
                <th>操作员名称*：</th>
                <td class="form-group">
                    <input check="notnull" type="text" id="opername"
                           value="${(commands?exists)?string(commands[0].opername,'')}" name="opername" size="30"/>
                </td>
            </tr>
        <#if !commands?exists>
            <tr>
                <th>登录密码*：</th>
                <td>
                    <input check="password" type="password" id="operpin"
                           value="${(commands?exists)?string(commands[0].operpin,'')}" name="operpin" size="30"/>
                </td>
            </tr>
            <tr>
                <th>确认密码*：</th>
                <td>
                    <input type="password" id="operpin1" name="operpin1" size="30"/>
                </td>
            </tr>
        </#if>

            <tr>
                <th>是否启用*：</th>
                <td>
                    <select id="flag" name="flag" class="form-control" style="width: 221px">
                        <option ${(commands[0].flag[0]=='1')?string('selected="selected"','')} value="1">是</option>
                        <option ${(commands[0].flag[0]=='0')?string('selected="selected"','')} value="0">否</option>
                    </select>
                </td>
            </tr>
            <tr>
                <th>启用时间*：</th>
                <td>
                    <#if commands?exists>
                        <input check="notnull" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})" type="text" id="startdate"
                               value="${commands[0].startdate?string('yyyy-MM-dd')}" name="startdate" size="30"/>
                    <#else >
                            <input check="notnull" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})" type="text" id="startdate" name="startdate" size="30"/>
                    </#if>

                </td>
            </tr>
            <tr>
                <th>过期时间*：</th>
                <td>
                <#if commands?exists>
                    <input check="notnull" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})" type="text" id="expdate"
                           value="${commands[0].expdate?string('yyyy-MM-dd')}" name="expdate" size="30"/>
                <#else >
                    <input check="notnull" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})" type="text" id="expdate" name="expdate" size="30"/>
                </#if>
                </td>
            </tr>


            <tr>
                <th>描述：</th>
                <td>
                    <textarea id="remark" name="remark">${commands[0].remark}</textarea>
                </td>
            </tr>
            <tr>
                <th >选择角色：</th>
                <td>
                    <table class="table  no-border">
                        <tr>
                            <td width="44%" class="text-center">待选角色</td>
                            <td class="text-center"></td>
                            <td width="44%" class="text-center">已选角色</td>
                        </tr>
                        <tr>
                            <td class="text-center">
                                <select name="unroles" multiple="multiple" id="select1"  class="mu-select form-control" style="width:100%;height:200px; padding:1px; ">
                                    <#if _availableRoles?exists>
                                        <#list _availableRoles as r>
                                            <option value="${r.code}">${r.name}</option>
                                        </#list>
                                    <#else>
                                        <@directive_role>
                                            <#list roles as r>
                                                <option value="${r.code}">${r.name}</option>
                                            </#list>
                                        </@directive_role>
                                    </#if>

                                </select>
                            </td>
                            <td class="text-center">
                                <span id="add">
                                <button type="button" class="btn btn-success btn-small" style="margin-top: 5px;width: 40px">
                                    <i class="fa fa-angle-right"></i>
                                </button>
                                </span>
                                <br/>
                                <span id="add_all">
                                <button class="btn btn-success btn-small" type="button" style="margin-top: 5px;width: 40px">
                                    <i class="fa fa-angle-double-right"></i>
                                </button>
                            </span>
                                <br/>
                                <span id="remove" style="margin-top: 5px">
                                <button class="btn btn-success btn-small" type="button" style="margin-top: 5px;width: 40px">
                                    <i class="fa fa-angle-left"></i>
                                </button>
                            </span>
                                <br/>
                                <span id="remove_all" style="margin-top: 5px">
                                <button class="btn btn-success btn-small" type="button" style="margin-top: 5px;width: 40px">
                                    <i class="fa fa-angle-double-left"></i>
                                </button>
                            </span>
                            </td>
                            <td class="text-center">
                                <select name="roles" multiple="multiple" class="form-control" id="select2" style="width:100%;height:200px; padding:1px;">
                                <#if _roles?exists>
                                    <#list _roles as r>
                                        <option value="${r.code}">${r.name}</option>
                                    </#list>
                                </#if>
                                </select>
                            </td>

                        </tr>
                    </table>
                </td>
            </tr>

        </table>
    </form>
</div>
<div style="text-align: center;margin-bottom: 10px">
    <button style="width: 120px" type="button" onclick="save()" class="btn btn-primary">提交</button>
    <button style="width: 120px" type="button" onclick="dialogClose();" class="btn">关闭</button>
</div>
<script>
    function save() {
        var data = checkForm($('#optForm'));
        if(data===false){
            return
        }

        if (data.operpin != data.operpin1) {
            layer.tips('两次密码输入不一致', '#operpin1', {tips: [2, '#78BA32']});
            return
        }
        var flags;
        if (data.opercode) {
            flags = data.flag + '${commands[0].flag[1..9]}';
        } else {
            flags = data.flag + '000000000';
        }
        var roles=[];
        $('#select2').find('option').each(function(){
            roles.push($(this).val())
        });

        data.flag=flags;
        data.startdate=data.startdate?new Date(data.startdate):null;
        data.expdate=data.expdate?new Date(data.expdate):null;
        data.operlevel=roles.join(",");

        post('pl/operator/save', data, function (result) {
            if (result.code == 0) {
                parent.table.ajax.reload();
                dialogClose();
            } else {
                alertError(result.message);
            }
        });

    }


    $('#add').click(function () {
        //获取选中的选项，删除并追加给对方
        $('#select1 option:selected').appendTo('#select2');
    });
    //移到左边
    $('#remove').click(function () {
        $('#select2 option:selected').appendTo('#select1');
    });
    //全部移到右边
    $('#add_all').click(function () {
        //获取全部的选项,删除并追加给对方
        $('#select1 option').appendTo('#select2');
    });
    //全部移到左边
    $('#remove_all').click(function () {
        $('#select2 option').appendTo('#select1');
    });
    //双击选项
    $('#select1').dblclick(function () { //绑定双击事件
        //获取全部的选项,删除并追加给对方
        $("option:selected", this).appendTo('#select2'); //追加给对方
    });
    //双击选项
    $('#select2').dblclick(function () {
        $("option:selected", this).appendTo('#select1');
    });
</script>
</body>
</html>
    </#compress>